/**
 * element 的文件大小 Formatter 实现
 *
 * @param fileSize 文件大小
 */
export const fileSizeFormatter = (fileSize) => {
  const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
  const srcSize = parseFloat(fileSize)
  const index = Math.floor(Math.log(srcSize) / Math.log(1024))
  const size = srcSize / Math.pow(1024, index)
  const sizeStr = size.toFixed(2) //保留的小数位数
  return sizeStr + ' ' + unitArr[index]
}


/**
 * 拼接字符
 *
 * @param word 传入的字符
 * @param lineBreakLength 换行的字符长度
 * @param mark 字符之间拼接的字符
 */
export const splicingCharacters = (word, lineBreakLength, mark) => {
  let str = "";
  const length = word.length//传入字符长度
  const remainLength = length % lineBreakLength//整除后剩余多少长度
  let num = remainLength === 0 ? length / lineBreakLength : Math.floor(length / lineBreakLength);//整除就取整，否则向下取整
  for (let i = 0; i < num; i++) {
    str += word.substring(i * lineBreakLength, lineBreakLength * (i + 1)) + mark//<br/>
  }
  if (remainLength !== 0) {
    const maxLength = num * lineBreakLength;
    str += word.substring(maxLength, maxLength + remainLength)
  }
  return str;
}
